<template>
  <div class="container">
    <div class="rulecontainer" v-if="showrules" @click="showrules=false">
      <img src="../assets/images/rule.png" class="rule">
    </div>
    <div class="start" v-if="ifstart">
      <div class="divTyping">
        <!-- 快来加入中秋美食集卡活动吧，有机会翻到<span style="font-weight:bold"> 隐藏卡片 </span>
        <br>
        集齐所有不同卡片可开奖获得礼品喔~
        <br> -->
        <el-button class="start_button" @click="ifstart=false">开始集卡</el-button>
        <el-button class="start_button rule_button" @click="showrules=true">游戏规则</el-button>
      </div>
    </div>
    <div class="activitytitle" style="width:100%;margin:40px 0 10px 0">
      <img src="../assets/images/activitytitle.png" width="100%">
      <span style="font-size:12px"><span style="font-weight:bold">{{count}}</span>人已集齐</span>
      <div style="color:#2c3e50;font-size:12px;margin-top:10px">请任意选择一张点开，开始集卡喔~</div>
    </div>
    <div class="cardcontainer">

      <cardrotateY v-for="(item,index) in 9" :key="index" style="width:30%;" @toResult="toResult"></cardrotateY>
    </div>
    <ParticleEffectButton :visible.sync="btnOps.visible" :animating.sync="btnOps.animating" :options="btnOps"
      class="legend_btn">
      我的图鉴
    </ParticleEffectButton>
    <!-- <button @click="btnOps.visible=!btnOps.visible">toggle</button> -->
  </div>
</template>

<script>
  import cardrotateY from "./cardrotateY.vue"
  import axios from 'axios'
  import ParticleEffectButton from "vue-particle-effect-buttons"
  export default {
    name: 'HelloWorld',
    components: {
      cardrotateY,
      ParticleEffectButton
    },
    props: {
      msg: String
    },
    data() {
      return {
        showrules: false,
        count: 2,
        ifstart: true,
        btnOps: {
          type: "circle",
          easing: "easeOutQuart",
          size: 2,
          particlesAmountCoefficient: 4,
          oscillationCoefficient: 2,
          duration: 500,
          color: function () {
            return Math.random() < 0.5 ? "#000000" : "#ffffff";
          },
          onComplete: () => {
            console.log("complete");
            var baseurl = this.$store.state.base_URL
            this.$router.push({
              path: baseurl + '/result',
              query: {}
            });
          },
          onBegin: () => {
            console.log("begin");
          },
          visible: true,
          animating: false
        },
      }
    },
    created() {
      if (this.$route.query.ifstart == 0) {
        this.ifstart = false
      }
      this.getawardcount()
    },
    methods: {
      getawardcount() {
        axios.post("/gacha/getgathercount").then(param => {
          console.log(param)
          var status = param.status
          if (status == 200) {
            this.count = param.data
          }
        })
      },
      typing(str) {
        var index = 0
        document.getElementById("divTyping").innerText = str.substring(0, index++);
      },
      toResult(index) {
        var base_URL = this.$store.state.base_URL
        console.log("当前抽中" + index + "号选手")
        var user_choose = []
        if (localStorage.getItem("user_choose")) {
          user_choose = JSON.parse(localStorage.getItem("user_choose"))
        }
        user_choose.push(index)
        user_choose = [...new Set(user_choose)]
        localStorage.setItem("user_choose", JSON.stringify(user_choose))
        setTimeout(() => {
          this.$router.push({
            path: base_URL + '/pickshow',
            query: {
              chooseid: index
            }
          });
        }, 1000);
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
  html,
  body {
    width: 100%;
    height: 100%;
  }

  /deep/ #try .rollbox_front,
  #try .rollbox_behind {
    background: transparent !important;
  }


  .container {
    width: 100%;
    height: 100%;
    background: url('../assets/images/legendbg.png');
    background-size: 100% 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    flex-direction: column;

    .rulecontainer {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      background: #00000070;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 4;
    }

    .rule {
      width: 80%;
      position: relative;
      top: -100px;
    }

    .start {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      background: url('../assets/images/startbg.jpeg');
      background-size: 100% 100%;
      z-index: 3;

      .divTyping {
        background-size: 100% 100%;
        padding: 1rem 0;
        position: absolute;
        width: 60%;
        bottom: 0%;
        left: 50%;
        transform: translateX(-50%);
      }

      .start_button {
        width: 80%;
        background: rgba(237, 170, 43, 1);
        border-color: white;
        font-weight: bold;
        color: white;
        margin: 0;
      }

      .rule_button {
        background: white;
        color: black;
        font-weight: normal;
        margin-top: 5px;
      }
    }

    .legend_btn {
      position: fixed;
      bottom: 10px;
      right: 10px;
    }

    ::v-deep .vue-particle-effect-button .particles-button {
      padding: 0.5rem;
      background: RGB(48, 72, 91);

    }

    .cardcontainer {
      width: 80%;
      margin: 0 auto;
      display: flex;
      align-items: center;
      justify-content: space-around;
      flex-wrap: wrap;
    }
  }
</style>